<template>
  <div>
      <div class="d-flex pt-2 pl-2">
        <span style="color:#5cd9e8">
          <icon name="chart-line"></icon>
        </span>
        <!-- <div class="d-flex">
          <span class="fs-xl text mx-2">各部门员工人数统计</span>
        </div> -->
      </div>
    <div id="centreLeft1Chart" style="width:300px; height: 320px;"></div>
  </div>
</template>

<script>
const echarts = require("echarts");
export default {
  props: ["listData"],
  watch: {
    listData(newValue) {
        console.log("监听")
      this.echartData = newValue;
      this.drawPie();
    }
  },
  data() {
    return {
      echartData: []
    };
  },
  mounted() {
    this.drawPie();
  },
  methods: {
    drawPie(sidebar) {
      // 基于准备好的dom，初始化echarts实例
      let myChartPieLeft = echarts.init(
        document.getElementById("centreLeft1Chart")
      );
      //  ----------------------------------------------------------------

      myChartPieLeft.setOption({
        title: {
          text: "人员学历分布",
          //subtext: '纯属虚构',
          left: "center",
          textStyle: {
            color: "#ffffff",
            fontSize: 20
          }
        },
        color: [
          "#37a2da",
          "#32c5e9",
          "#9fe6b8",
          "#ffdb5c",
          "#ff9f7f",
          "#fb7293",
          "#e7bcf3",
          "#8378ea"
        ],
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        toolbox: {
          show: true
        },
        calculable: true,
        legend: {
          orient: "horizontal",
          icon: "circle",
          bottom: 0,
          x: "center",
          data: [
            "大学本科",
            "研究生",
            "高中",
            "初中",
            "小学",
            "大学专科",
            "硕士",
            "其他"
          ],

          textStyle: {
            color: "#fff"
          }
        },
        series: [
          {
            name: "人员学历分布表",
            type: "pie",
            radius: [10, 60],
            roseType: "area",
            center: ["50%", "40%"],
             data:this.echartData
          }
        ]
      });
      // -----------------------------------------------------------------
      // 响应式变化
      window.addEventListener("resize", () => myChartPieLeft.resize(), false);
      //侧边栏变化
      if (sidebar) {
        myChartPieLeft.resize();
      }
    }
  },
  destroyed() {
    window.onresize = null;
  }
};
</script>
